由於此題較為簡單,不再特別贅述
#include <iostream>
using namespace std;
int main(){
string s;
int num=0;
while(getline(cin,s)){
for(int i=0;i<s.length();i++){
if(s[i]!='"') cout<<s[i];
else if (!(num%2)) {
cout<<"``";
num++;
}
else {
cout<<"''";
num++;
}
}
cout<<endl;
}
}
bool compare(int a, int b) {
return a > b;
}
sort(arr, arr + 6, compare);
參考延伸閱讀:https://officeguide.cc/cpp-sort-function-tutorial-examples/
由於此題我在寫的時候有點卡住,因此我有在瘋狂程設找一些大神寫的程式碼做為參考!
#include<bits/stdc++.h>
using namespace std;
int a[10000],N,M;
bool comp(int x,int y){
if(x%M!=y%M)return x%M<y%M;//因為Mod M的數值越小會排在越前面
if(abs(x%2)!=abs(y%2))return x%2;//代表一奇一偶。因為數值有負數所以要用絕對值來看
if(x%2)return x>y;//若兩個都為奇數則數值大的奇數在前
return x<y;
}
int main(){
while(cin>>N>>M){
cout<<N<<" "<<M<<endl;
for(int i=0;i<N;i++){
cin>>a[i];
}
sort(a,a+N,comp);
for(int i=0;i<N;i++){
cout<<a[i]<<endl;
}
if(N==0&&M==0){
break;
}
}
}
#include<iostream>
#include<string>
using namespace std;
int main() {
int a, b, carry = 0, len, bit = 0;
string str_a, str_b;
while (cin >> a >> b) {
if (!(a || b)) break;
str_a = to_string(a);
str_b = to_string(b);
if (str_a.length() > str_b.length()) len = str_a.length();
else len = str_b.length();
for (int i = len; i > 0; i--) {
if (bit) {
if ((a % 10 + b % 10) + 1 > 9) {
carry++;
bit = 1;
}
else bit = 0;
}
else {
if ((a % 10 + b % 10) > 9) {
carry++;
bit = 1;
}
}
a /= 10;
b /= 10;
}
if (carry == 0) cout << "No carry operation." << endl;
else if (carry == 1) cout << carry << " carry operation." << endl;
else cout << carry << " carry operations." << endl;
carry = 0; len = 0; bit = 0;
}
}